package com.jhhc.BDMS.System;

import com.jhhc.BDMS.System.Pojo.RegionArea;
import com.jhhc.BDMS.System.Serivce.BDMS_SYS_PROJECTService;
import com.jhhc.BDMS.System.Util.GetADMINMAPUtil;
import com.jhhc.BDMS.System.entity.BDMS_SYS_PROJECT;
import com.jhhc.BDMS.System.entity.ProjectInfo;
import com.jhhc.BDMS.System.entity.SystemParam;
import com.jhhc.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Api(value="系统数据相关服务",tags={"系统数据相关服务"})
@RestController
@RequestMapping(value = "BDMS",headers = "Accept=application/json")
public class SysetmController {
    @Autowired
    private GetADMINMAPUtil getADMINMAPUtil;

    @Autowired
    private BDMS_SYS_PROJECTService bdmsSysProjectService;



    //获取行政区域
    @ApiOperation(value = "获取边界信息")
    @RequestMapping( value = "System/GetAdminMap", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult getTideHourData(@RequestParam Integer ProjectId){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        RegionArea regionArea =getADMINMAPUtil.getAdminMap(ProjectId);
        jsonResult.setData(regionArea);
        return  jsonResult;
    }


    //获取行系统列表
    @ApiOperation(value = "获取系统列表")
    @RequestMapping( value = "System/GetSystems", headers = "Accept=application/json", method = RequestMethod.POST)
    public JsonResult getSystems(@RequestBody SystemParam param){
        JsonResult jsonResult = new JsonResult();
        if (param.getSystem() != null && !"".equals(param.getSystem())) {
            List<BDMS_SYS_PROJECT> bdmsSysProjects = bdmsSysProjectService.
                    queryBySystemType(param.getSystem());
            if (bdmsSysProjects != null && bdmsSysProjects.size() > 0) {
                List<ProjectInfo> projectInfos = new ArrayList<>();
                for (BDMS_SYS_PROJECT bdmsSysProject : bdmsSysProjects) {
                    ProjectInfo projectInfo = new ProjectInfo();
                    projectInfo.setCommon("true".equals(bdmsSysProject.getCommon()));
                    projectInfo.setPnm(bdmsSysProject.getPnm());
                    projectInfo.setPid(bdmsSysProject.getPid());
                    projectInfo.setSystemtp(bdmsSysProject.getSystemtp());
                    projectInfos.add(projectInfo);
                }
                jsonResult.setData(projectInfos);
            }else {
                jsonResult.setData("查询" + param.getSystem() + "信息为空");
            }
        }else {
            jsonResult.setData("参数信息不能为空");
        }
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        return  jsonResult;
    }
    //修改常用
    @ApiOperation(value = "修改常用系统")
    @RequestMapping( value = "System/UpdateCommon", headers = "Accept=application/json", method = RequestMethod.POST)
    public JsonResult updateCommon(@RequestBody SystemParam param){
        JsonResult jsonResult = new JsonResult();
        BDMS_SYS_PROJECT bdmsSysProject = bdmsSysProjectService.queryByCommon();
        if (bdmsSysProject != null) {
            bdmsSysProjectService.updateByPid(bdmsSysProject.getPid(),"false");
            int result = bdmsSysProjectService.updateByPid(param.getPid(),"true");
            jsonResult.setData(result);
        }else {
            int result = bdmsSysProjectService.updateByPid(param.getPid(),"true");
            jsonResult.setData(result);
        }
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        return  jsonResult;
    }










//    @Autowired
//    private GetTxtUitl getTxtUitl ;
//
//    @RequestMapping(headers = "Accept=application/json", method = RequestMethod.GET)
//    public JsonResult getTideHourData(){
//
//        JsonResult jsonResult = new JsonResult();
//
//        // System.out.println(getTxtUitl.InsertPoint2().size());
//
//        System.out.println(getTxtUitl.in2(getTxtUitl.InsertPoint2())+"in2");
////        System.out.println(getTxtUitl.InsertPoint().toString()+"TOSTRING");
////        System.out.println( getTxtUitl.in(  getTxtUitl.InsertPoint()));
//        return  jsonResult;
//    }
}
